<template>
  <view class="index">
    <view>
      <van-field
        :value="content"
        placeholder="发布消息，生意上门"
        :border="false"
        type="textarea"
        :multiple="true"
        :autosize="{ minHeight: 100 }"
        @change="onChange"
      />
    </view>
    <view class="padding">
      <Upload v-model="fileList" :maxCount="9" />
    </view>
    <view class="padding">
      <van-button
        size="large"
        type="primary"
        block
        color="#006CFF;"
        @tap="publish"
      >
        发布
      </van-button>
    </view>
  </view>
</template>

<script>
import Taro from '@tarojs/taro'
import Upload from '@components/common/upload/index'
import { publish } from '@requests/circle'
import { getParam, toast, goBack } from '@utils/index'

export default {
  name: 'ReleaseCars',
  data() {
    return {
      content: '',
      fileList: []
    }
  },
  components: { Upload },
  methods: {
    onChange(event) {
      this.content = event.detail
    },
    publish() {
      if (this.content == '') {
        Taro.showToast({
          title: '请填写发布消息',
          icon: 'none'
        })
        return
      }
      if (this.fileList.some(item => item.status != 'done')) {
        Taro.showToast({
          title: '图片还未上传成功，请稍等',
          icon: 'none'
        })
        return
      }
      publish({
        content: this.content,
        imgs: this.fileList.map(i => {
          return i.path
        })
      }).then(res => {
        toast.success('发布成功').then(() => {
          goBack()
        })
      })
    }
  }
}
</script>

<style>
.padding {
  padding: 24rpx 24rpx;
}
</style>
